; ---Includes
include lib.asm

.MODEL small ;one data, one code segment, stack and data segment are grouped
.STACK 1024 ;stack, 1024 bytes

; --- Macros

.DATA ;data segment, static variables
; --- Constants

; --- Types

; --- Variables	
	InstalVar
	x dw 100
	y dw 100
	sizex dw 40
	sizey dw 80	
	color db 5
	
.CODE ;code segment
.STARTUP ; start main, sets ds to beginning of data segment, updates ss to ds and adjusts sp acordingly	

	MSetVideoMode 13h
	MInitMouse
	mov cx,2
draw:
	;Clear previous mouse pointer
	MDrawRect 0,mousex,mousey,2,2
	MUpdateMouse
	;Calculate
	mov color,5
checkrect:	
	MPointInRect mousex,mousey,x,y,sizex,sizey,notinrect,inrect
notinrect:	
	jmp endcheckrect
inrect:
	mov ax,1
	cmp ax,mousestate
	jne endcheckrect
	mov color,120
endcheckrect:
	;Draw rectangle
	MDrawRect color,x,y,sizex,sizey
	;Draw Mouse pointer
	MDrawRect 1,mousex,mousey,2,2
	MUpdateScreenMode13
	;Draw mouse state
	MDrawInt 0,0,mousestate
	cmp cx,mousestate	; if the second mouse button is pushed the loop ends
jne draw
	MRestoreVideoMode	
.EXIT
; ---Procedures
	InstalPrintInt
	InstalRandInt
	IntstalCopyData
	InstalDrawRect
END
